<%@page import="java.security.SecureRandom"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<c:set var="path" value="${pageContext.request.contextPath}" />
<title>WebMaven</title>
<script src="${path}/scripts/jquery/jquery-1.9.0.min.js"
	type="text/javascript"></script>
<%
	SecureRandom random = new SecureRandom();
	random.setSeed(4771);
	double _csrf = random.nextDouble();
	session.setAttribute("_csrf", _csrf);
%>
<script type="text/javascript">
	$(function() {
		$("#verifyImg").click(
				function() {
					$("#message").text("");
					$(this).attr(
							"src",
							"<c:url value='/user/user/verify.html'/>?"
									+ Math.floor(Math.random() * 100));
				});
		$("#verifyCode").keyup(function() {
			var verifyCodeValue = $("#verifyCode").val().replace("/\s/g", "");
			if (verifyCodeValue.length == 5) {
				$.ajax({
					url : "<c:url value='/user/user/checkVerifyCode.html'/>",
					type : "POST",
					data : {
						"verifyCodeValue" : verifyCodeValue
					},
					success : function(response) {
						if (response == "ok") {
							$("#message").text("验证码校验成功");
						} else {
							$("#message").text("验证码校验失败，点击验证码刷新后再次尝试");
						}
					}
				});
			}
		});
	});
</script>
</head>
<body>
	<div align="center">
		<h2>RBACDemo</h2>
		<form action="<c:url value='/user/user/check.html'/>" method="post">
			<table>
				<tr>
					<td>用户名：</td>
					<td><input type="text" id="username" name="username" /></td>
				</tr>
				<tr>
					<td>密码：</td>
					<td><input type="password" id="password" name="password" /></td>
				</tr>
				<tr>
					<td>验证码：</td>
					<td><input type="text" id="verifyCode" name="verifyCode"
						maxlength="5" value="" /> <img id="verifyImg" name="verifyImg"
						alt="看不清，换一张？" src="<c:url value='/user/user/verify.html'/>"
						style="margin-bottom: -4px"></td>
				</tr>
				<tr>
					<td colspan="2" align="center"><div id="message"
							style="color: red"></div></td>
				</tr>
				<tr>
					<td colspan="2" align="center"><input type="submit" value="登录" />
						<input type="reset" value="重置" /></td>
				</tr>
			</table>
			<input type="hidden" name="_csrf" value="<%=_csrf%>" />
		</form>
		<div style="color: red">
			<c:out value="${error}"></c:out>
		</div>
	</div>
</body>
</html>